package com.example.phpclient;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.MenuItem;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.appcompat.widget.Toolbar;

import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import com.example.phpclient.content.UploadPicDebug;
import com.example.phpclient.content.manager_list;
import com.example.phpclient.fragment.Manager_three_Fragment;
import com.example.phpclient.fragment.Manager_three_Fragment1;
import com.example.phpclient.fragment.fragment_qd;
import com.google.android.material.navigation.NavigationView;

import static com.example.phpclient.R.string.navigation_drawer_close;

public class drawer_activity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
    private Toolbar toolbar;
    private DrawerLayout drawerLayout;
    FragmentManager manager;
    FragmentTransaction transaction;
    NavigationView navigationView;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_manager);
        initDrawerLayout();
         manager =getSupportFragmentManager();
         transaction = manager.beginTransaction();

    }
    private void initDrawerLayout(){
        toolbar =findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        drawerLayout =(DrawerLayout) findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.navigation_drawer_open, navigation_drawer_close);
        drawerLayout.addDrawerListener(toggle);
        toggle.syncState();
        navigationView = (NavigationView)findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);
    }

    @Override
    public void onBackPressed() {
        if (drawerLayout == null)return;
        if (drawerLayout.isDrawerOpen(GravityCompat.START)){
            drawerLayout.closeDrawer(GravityCompat.START);
        }
        else {
            super.onBackPressed();
            }

    }

    @Override
    public boolean onNavigationItemSelected(@NonNull MenuItem item) {
        int id=item.getItemId();
        Intent intent = null;
        switch (id){
            case R.id.nav_inform:
                transaction.replace(R.id.content_layout,new Manager_three_Fragment1());
                transaction.commit();
                if (drawerLayout.isDrawerOpen(GravityCompat.START)){
                    drawerLayout.closeDrawer(GravityCompat.START);
                }
                break;
            case R.id.nav_qiandao:
                intent = new Intent(drawer_activity.this, manager_list.class);
                startActivity(intent);
                Toast.makeText(drawer_activity.this, "正在开发中...", Toast.LENGTH_SHORT).show();
                break;
            //可以更多，只要在menu的布局文件里声明。
            case R.id.nav_student:
                intent = new Intent(drawer_activity.this, UploadPicDebug.class);
                startActivity(intent);
                Toast.makeText(drawer_activity.this, "上传图片测试...", Toast.LENGTH_SHORT).show();
                break;
            //可以更多，只要在menu的布局文件里声明
        }
        return false;
    }
}
